<template>
  <div class="menu">
    <el-menu
      active-text-color="#4688F6"
      background-color="#fff"
      text-color="#2C3A4D"
      default-active="2"
      :default-openeds="['/zldt']"
      router
      class="el-menu-vertical-demo"
      :collapse="props.isCollapse"
      :ellipsis="false"
      @open="handleOpen"
      @close="handleClose"
    >
      <template
        v-for="item in fiterRoutes.filter((item) => !item.hidden)"
        :key="item.id"
      >
        <el-sub-menu
          class="menu-content"
          v-if="item.children && item.children.length > 0"
          :index="item.path"
        >
          <template #title>
            <el-icon>
              <component v-if="item.meta" :is="item.meta.icon"></component>
            </el-icon>
            <!-- <el-icon><location /></el-icon> -->
            <span v-if="item.meta">{{ item.meta.title }}</span>
          </template>
          <!-- 二级菜单 -->
          <el-menu-item
            v-for="item2 in item.children.filter((item) => !item.hidden)"
            :key="item2.id"
            :index="item2.path"
            :style="item2.children ? 'display: none' : null"
          >
            {{ item2.children ? null : item2.meta.title }}
          </el-menu-item>
        </el-sub-menu>
        <el-menu-item v-else :index="item.path">
          <template #title>
            <el-icon>
              <component v-if="item.meta" :is="item.meta.icon"></component>
            </el-icon>
            <!-- <el-icon><location /></el-icon> -->
            <span v-if="item.meta">{{ item.meta.title }}</span>
          </template>
        </el-menu-item>
      </template>
    </el-menu>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { routes } from "@/router/index";
let fiterRoutes = routes.filter((item) => {
  return item.path === "/";
});
fiterRoutes = fiterRoutes[0].children;

const router = useRouter();
const props = defineProps({
  isCollapse: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["menuChange"]);
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
onMounted(() => {
  console.log(router.options.routes);
});
</script>
<style lang="scss" scoped>
.el-menu-item:hover {
  border-left: #4688f6 solid 6px !important;
  background-color: #e2eff9 !important;
  color: #38b2ff !important;
}

.menu {
  display: flex;
  height: auto;
  min-height: 100vh;
  .menu-content {
    // min-height: calc(100vh - 60px);
    min-width: 280px;
  }
}
</style>
